package com.bdqn.mr.mj;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class MapJoinDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException, URISyntaxException {
        Job job = Job.getInstance(new Configuration());

        job.setJarByClass(MapJoinDriver.class);
        job.setMapperClass(MapJoinMapper.class);

        job.setMapOutputKeyClass(TableBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        // 添加缓存文件
        job.addCacheFile(new URI("file:///D:/mr/mapjoin/cache/pd.txt"));

        // 设置 ReduceTask 的数量为0 : 没有reduce阶段
        job.setNumReduceTasks(0);

        FileInputFormat.setInputPaths(job,new Path("D:\\mr\\mapjoin\\input"));
        FileOutputFormat.setOutputPath(job,new Path("D:\\mr\\mapjoin\\output"));

        System.exit(job.waitForCompletion(true)?0:1);
    }
}
